package com.yssw.client.service.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import com.yssw.common.utils.DateUtils;
import com.yssw.model.vo.client.ClientUserSignLogVo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yssw.client.mapper.ClientUserSignLogMapper;
import com.yssw.client.domain.ClientUserSignLog;
import com.yssw.client.service.IClientUserSignLogService;

/**
 * 用户签到记录Service业务层处理
 *
 * @author yssw
 * @date 2023-03-29
 */
@Service
public class ClientUserSignLogServiceImpl implements IClientUserSignLogService {
    @Autowired
    private ClientUserSignLogMapper clientUserSignLogMapper;

    /**
     * 查询用户签到记录
     *
     * @param id 用户签到记录主键
     * @return 用户签到记录
     */
    @Override
    public ClientUserSignLog selectClientUserSignLogById(Long id) {
        return clientUserSignLogMapper.selectClientUserSignLogById(id);
    }

    /**
     * 查询所有用户签到记录列表
     *
     * @param clientUserSignLog 用户签到记录
     * @return 用户签到记录
     */
    @Override
    public List<ClientUserSignLog> selectClientUserSignLogList(ClientUserSignLog clientUserSignLog) {
        return clientUserSignLogMapper.selectClientUserSignLogList(clientUserSignLog);
    }

    /**
     * 查询用户签到记录列表
     *
     * @param getMonth 月份
     * @return 用户签到记录
     */
    @Override
    public ClientUserSignLogVo selectClientUserSignLogListByUserId(String getMonth, Long userId) throws ParseException {
        ClientUserSignLogVo logVo = new ClientUserSignLogVo();

        DateFormat format=new SimpleDateFormat(DateUtils.YYYY_MM);

        if (ObjectUtils.isEmpty(getMonth)) {
            String s = format.format(DateUtils.getNowDate());
            getMonth= s;
        }
        logVo.setGetMonth(format.parse(getMonth));
        List<ClientUserSignLog> clientUserSignLogs = clientUserSignLogMapper.selectClientUserSignLogListByUser(getMonth, userId);
        logVo.setClientUserSignLogList(clientUserSignLogs);

        return logVo;
    }

    /**
     * 新增用户签到记录
     *
     * @param clientUserSignLog 用户签到记录
     * @return 结果
     */
    @Override
    public int insertClientUserSignLog(ClientUserSignLog clientUserSignLog) {
        clientUserSignLog.setCreateTime(DateUtils.getNowDate());
        return clientUserSignLogMapper.insertClientUserSignLog(clientUserSignLog);
    }

    /**
     * 修改用户签到记录
     *
     * @param clientUserSignLog 用户签到记录
     * @return 结果
     */
    @Override
    public int updateClientUserSignLog(ClientUserSignLog clientUserSignLog) {
        clientUserSignLog.setUpdateTime(DateUtils.getNowDate());
        return clientUserSignLogMapper.updateClientUserSignLog(clientUserSignLog);
    }

    /**
     * 批量删除用户签到记录
     *
     * @param ids 需要删除的用户签到记录主键
     * @return 结果
     */
    @Override
    public int deleteClientUserSignLogByIds(Long[] ids) {
        return clientUserSignLogMapper.deleteClientUserSignLogByIds(ids);
    }

    /**
     * 删除用户签到记录信息
     *
     * @param id 用户签到记录主键
     * @return 结果
     */
    @Override
    public int deleteClientUserSignLogById(Long id) {
        return clientUserSignLogMapper.deleteClientUserSignLogById(id);
    }
}
